package feature;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * Decription
 * Date 2017/10/7 15:08
 * authur MangoDai
 **/
public class VolatileDemo {
    public static volatile int race = 0;
    static Lock lock = new ReentrantLock();
    public static synchronized void increase() {
        race++;
    }
    private static final int THREADS_COUNT = 20;

    public static void main(String[] args) {
        Thread[] threads = new Thread[THREADS_COUNT];
        for (Thread thread : threads) {
            thread = new Thread( () -> {
                for(int i = 0; i < 10000; i++) {
                    increase();
                }
            });
            thread.start();
        }
        while (Thread.activeCount() != 1);
        System.out.println("race = " + race);
    }
}
